package com.zone;

import java.lang.reflect.Proxy;
import java.util.Map;

/**
 * @author: zongzi
 * @description: TODO
 * @date: 2023/11/26
 */
public class MapperProxyFactory<T> {

    private final Class<T> mapperInterface;

    public MapperProxyFactory(Class<T> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    /**
     * 生成接口代理对象
     *
     * @param sqlSession
     * @return
     */
    public T newProxy(Map<String, String> sqlSession) {
        MapperProxy<T> mapperProxy = new MapperProxy<>(mapperInterface, sqlSession);
        return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(),
                new Class[]{mapperInterface},
                mapperProxy);
    }
}
